<template>
<div>
  <div>
    <div>
      <van-radio-group v-model="workid" v-for="i in dict" :key="i" @click="get_type(i.id)">
        <van-radio :name="i.id">{{ i.name }}</van-radio>
      </van-radio-group>
    </div>
     <div v-if="this.workid==1">
       <p v-for="j in prams" :key="j">
         <van-field v-if="j.type=='field'" :label="j.lable" v-model="values[j.lable]"></van-field>
         <select name="" id="" v-if="j.type=='select'" v-model="values[j.lable]">
           <option :value="i.name" v-for="i in j.values" :key="i">{{i.name}}</option>
         </select>

         <el-date-picker
             v-model="values[j.lable]"
             type="datetime"
             placeholder="开始时间"
             v-if="j.type=='datetime'"
         />

         <el-date-picker
             v-model="values[j.lable]"
             type="datetime"
             placeholder="结束时间"
             v-if="j.type=='datetime'"
         />
         <van-uploader v-if="j.type=='file'"  :after-read="upload" ></van-uploader>
       </p>
       <van-button @click="get_audit()">选择审核人</van-button>
       <el-dialog v-model="dialogTableVisible" title="Shipping address"  >
         <el-tree :data="data" :props="defaultProps" show-checkbox @check-change="hode_get"  node-key="type"/>
         <van-button @click="show_flask"> 确定</van-button>
       </el-dialog>

       <van-button @click="submit">提交</van-button>
     </div>
  </div>
</div>
</template>

<script>
export default {
name: "workflak",
  data(){
  return{
  list:[],
    prams:[],
    value1:'',
    value2:'',
    values:[],
    dict: [],
    radio: '',
    workid:1,
    pic:'',
    dialogTableVisible:false,
    lists:[],
    data: [],
    node_id:[]
  }
  },
  methods:{
    show_flask(){
      this.dialogTableVisible=false
    },
    hode_get(data){
      console.log(data)
      this.lists.push(data)
      if (data.type==3){
        this.node_id.push(data.id)
      }
      console.log(this.node_id)
    },
  get_audit(){
    this.myaxios('http://localhost:5000/post_task','get',{})
        .then(res=>{
          console.log(res)
          this.data=res.data.res
        })
    // 获取公司下的部门
    this.dialogTableVisible=true

  },
    get_type(id){
      console.log(id)
      this.workid=id
    },
    get_all()
    {
      this.myaxios('http://localhost:5000/post_liulan', 'get', {})
          .then(res => {
            console.log(res)
            this.dict = res.data.list
          })
    },
    upload(file){
      let data=new FormData
      data.append('file',file.file)
      const axios=this.axios.create({withCredentials:false})
      axios({
        url:'http://localhost:5000/upload',
        method:'post',
        data:data
      })
      .then(res=>{
        console.log(res)
        console.log(res.data.filename)
        this.pic=res.data.filename
      })
    },
    submit(){
      // console.log(this.value1)
      console.log(this.values)
      this.values['userid']=localStorage.getItem('userid')
      if (this.pic){
        this.values['文件']=this.pic
      }
      if (this.values['开始时间']!=null){
        if (this.values['开始时间']>this.values['结束时间']){
          this.$toast.fail('时间不对请重新选择')
        }
      }
      console.log(this.values)
      let datas=[]
      datas=this.values
      this.myaxios('http://localhost:5000/post_task','post',{'values':datas,'node_id':this.node_id})
          .then(res=>{
            console.log(res)
          })

    },
  get_qingj(){
    this.myaxios('http://localhost:5000/get_worf','get',{'id':this.workid})
    .then(res=>{
      console.log(res)
      this.list=res.data.dict
      this.prams=JSON.parse(res.data.dict)

    })
  }
  },
  mounted() {
  this.get_qingj()
  this.get_all()
  }
}
</script>

<style scoped>

</style>
